<?php
/**
 * Created by PhpStorm.
 * User: lixy
 * Date: 2016/1/6
 * Time: 9:13
 */


use yii\helpers\Html;
use yii\helpers\Url;
use app\lib\WeixinUtils;

/* @var $this yii\web\View */
/* @var $content string 字符串 */


$web = Url::to("@web");


/*
$viewGooods = [];
$tmp = [];
$m = 0;
$goods_count = count($goods);
for ($i = 0; $i < $goods_count; ++$i) {

    $tmp[] = $goods[$i];
    $m = $m + 1;
    if ($m == 2 || $i == $goods_count - 1) {
        $viewGooods[] = $tmp;
        $m = 0;
        $tmp = [];
    }
}
*/
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">

    <link rel="stylesheet" href="<?= $web ?>/css/wx/new_card_list_take.css"/>
    <script type="application/javascript" src="<?= $web ?>/js/jquery.js"></script>
    <script type="application/javascript" src="<?= $web ?>/js/wx/pager_goods_chose.js"></script>
    <script type="application/javascript" src="<?= $web ?>/js/tools.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var w = $(document).width();
            if (w > 640) {
                w = 640;
            }
            $("body").css("font-size", w * 100 / 320);

            $("#btnExchange").click(function () {
                var stock = $("#hidden_good_stock").val();
                if (stock <= 0) {
                    return;
                }
                var good_code = $("#hidden_good_code").val();
                var code_id = $("#hidden_card_code_id").val();
//                window.location.href = "<?//=Url::to(["wx-biz/confirm-good-order"]);?>//?good_code=" + good_code + "&id=" + code_id;
                window.location.href = "<?=Url::to(["wx-biz/gift-receiver-form"]);?>?good_code=" + good_code + "&id=" + code_id
            });

            $(".goods-detail-frame .goods-detail-content .btn-close").click(function () {
                $(".goods-detail-frame").hide();
                isDetailShow = false;

                isPager = true;
            });
        });
        var isDetailShow = false;
        //弹出隐藏层
        function showGoodInfo(title, msg, goods_code, stock) {
            $(".goods-detail-frame").show();
            $("#goods_name").text(title);
            $("#goods_detail").html(msg);

            $("#hidden_good_code").val(goods_code);

            $("#btnExchange").hide();
            $("#stock").text("...");

            $("#stock").text(stock);
            $("#hidden_good_stock").val(stock);

            if (stock > 0) {
                $("#btnExchange").show();
                $("#btnExchange").css("background-color", "#d7000f");
                $("#btnExchange span").text("立即兑换");
            } else {
                $("#btnExchange").show();
                $("#btnExchange").css("background-color", "#a7a7a7");
                $("#btnExchange span").text("库存不足");
            }

            isDetailShow = true;
            isPager = false;

//			var data = {};
//            data.goods_code = goods_code;
//			returnjson("<?//=Url::to(["wx-biz/get-goods-stock"])?>//", data, true, function(t){
//				$("#stock").text(t.stock);
//				$("#hidden_good_stock").val(t.stock);
//
//				if(t.stock>0){
//					$("#btnExchange").show();
//					$("#btnExchange").css("background-color", "#09bb07");
//					$("#btnExchange span").text("立即兑换");
//				}else{
//					$("#btnExchange").show();
//					$("#btnExchange").css("background-color", "#a7a7a7");
//					$("#btnExchange span").text("库存不足");
//				}
//
//			});
        }

        //获取产品详情
        function getGoodInfo(card_id, good_name, good_code, isShowStock) {
            var data = {};
            data.isShowStock = isShowStock;
            data.good_code = good_code;
            data.card_id = card_id;

            $(".goods-detail-frame").show();
            $("#goods_name").text(good_name);
            $("#goods_detail").html("正在加载...");
            $("#btnExchange").hide();
            $("#stock").text("...");


            isDetailShow = true;
            isPager = false;


            returnjson("<?=Url::to(["wx-biz/get-good-handle"])?>", data, true, function (re) {
                if (re.flag == 1) {
//                    showGoodInfo(re.good.GOODS_NAME, re.good.GOODS_DETAIL_HTML, good_code, re.stock);
                    $("#goods_detail").html(re.good.GOODS_DETAIL_HTML);
                    $("#hidden_good_code").val(good_code);

                    $("#stock").text(re.stock);
                    $("#hidden_good_stock").val(re.stock);

                    if (re.stock > 0) {
                        $("#btnExchange").show();
                        $("#btnExchange").css("background-color", "#09bb07");
                        $("#btnExchange span").text("立即兑换");
                    } else {
                        $("#btnExchange").show();
                        $("#btnExchange").css("background-color", "#a7a7a7");
                        $("#btnExchange span").text("库存不足");
                    }
                } else {
                    alert(re.msg);
                    return false;
                }
            });
        }

        //兑换朵拉币
        function exchange_coin() {
            if (confirm('您想把此礼品兑换成{0}个朵拉币吗?'._format(<?=$doracoin["PRICE"]?>))) {
                var data = {};
                data.type_id = 1;
                data.order_id = "<?=$doracoin["ORDER_ID"]?>";
                data.exchange_id = "<?=$doracoin["ID"]?>";

                var re = returnjson("<?=Url::to(["wx-home/receive-dora-coin-handle"])?>", data);
                if (re.flag == 1) {
                    alert('兑换成功!');
                    window.location.href = "<?=Url::to(["wx-biz/view-gift-nav"]);?>?code_id=" + "<?= $card_code_id ?>";
                } else {
                    alert(re.msg);
                    return false;
                }
            }
        }


        var goodsList = <?=json_encode($goods) ?>;
        //        $(function($){
        //            var isbuy=$("#hidden_isbuy").val();
        //
        //            if(isbuy==0){
        //                //不购买
        //                $('.ma_top').hide();
        //            }
        //        });
    </script>

    <title>兑换礼物</title>

</head>

<body style="background-color:#FFFFFF;">
<input type="hidden" id="hidden_good_code" value=""/>
<input type="hidden" id="hidden_good_stock" value=""/>
<input type="hidden" id="hidden_card_code_id" value="<?= $card_code_id ?>"/>

<div class="wrapper">
    <div class="page">
        <img style="width: 100%;" tag="<?= $card['CARD_TWO'] ?>" src="<?= $web ?>/img/wx/default_goods_show.png">
    </div>
    <?php
    for ($i = 0; $i < sizeof($goods); $i++) {
        $good = $goods[$i];
        ?>
        <div class="page">
            <img style="width: 100%;" src="<?= $web ?>/img/wx/default_goods_show.png"
                 onclick="getGoodInfo('<?= $card['ID'] ?>','<?= $good['GOODS_NAME'] ?>','<?= $good['GOODS_CODE'] ?>', 1)">
        </div>
        <?php
    }
    ?>
    <div class="page">
        <img style="width: 100%;" tag="<?= $card['CARD_THREE'] ?>" src="<?= $web ?>/img/wx/default_goods_show.png">
    </div>
</div>
<div class="nav-panel">
    <div class="scroll-btn up">
    </div>
    <div class="scroll-btn down">
    </div>
    <nav>
        <ul>
            <li class="nav-btn active"></li>
            <?php
            for ($i = 0; $i < sizeof($goods); $i++) {
                ?>
                <li class="nav-btn"></li>
                <?php
            }
            ?>
            <li class="nav-btn"></li>
        </ul>
    </nav>
</div>

<div class="goods-detail-frame">
    <div class="goods-detail-mask"></div>
    <div class="goods-detail-content">
        <div style="height: 0.34em;">
            <a href="#" class="btn-close"
               style="background-image: url('<?= $web ?>/img/wx/card_list_img/btn-close.png');"></a>
        </div>
        <div style="height: 0.42em; border-bottom: 1px #cccccc solid; background-color: #ffffff;">
            <div class="goods-name-text">
                <div id="goods_name" style="font-size: 0.16em;">商品名称</div>
            </div>
        </div>
        <div id="goods_detail_frame" style="height: 3em; background-color: #ffffff; overflow: auto;">
            <div id="goods_detail" class="content-frame">
            </div>
        </div>
        <div style="background-color:#f4f4f4; height:0.6em;">
            <div style="line-height:0.6em; margin-left:0.1em;">
                <span style="font-size:0.12em; float:left; color:#666666;">库存：剩余商品数量</span>
                <span id="stock" style="font-size:0.12em; float:left; color:#d7000f;">...</span>
            </div>
            <div id="btnExchange"
                 style="display:none; width:1em; height:0.4em; margin-top:0.1em; line-height:0.4em; float:right; text-align: center; margin-right:0.1em; background-color:#d7000f; border-radius: 0.02em;">
                <span style="font-size:0.14em; color:#ffffff; float:left; width:100%; text-align: center;">立即兑换</span>
            </div>

        </div>
    </div>
</div>

<div class="exchange-dorabi-frame">
    <div>都不喜欢?</div>
    <div style="color: #d7000f;" onclick="exchange_coin()">换成多拉币吧</div>
    <div>,去挑选更多礼物 ></div>
</div>

</body>
</html>

